﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Text;

namespace ATW.MT.SellManage
{
    public partial class _addConn : System.Web.UI.Page
    {
        BUS.bus_C_Conn cc = new BUS.bus_C_Conn();
        protected void Page_Load(object sender, EventArgs e)
        {
            if (Session["UserInfo"] == null)
            {
                Response.Redirect("../Main/Login.aspx");
            }
        }
        protected void queryButton_Click(object sender, EventArgs e)
        {
            string desc = txtDesc.Text.Trim();
            string code = txtCode.Text.Trim();
            try
            {
                if (desc == "")
                {
                    Tips("连接方式不能为空！");
                    return;
                }
                if (code == "")
                {
                    Tips("请输入连接方式缩写！");
                    return;
                }
                if (!CommonClass.common.filterChar(desc) || !CommonClass.common.filterChar(code))
                {
                    Tips("输入参数中含有非法字符！");
                    return;
                }
                if (cc.IsConnExist(desc))
                {
                    Tips("连接方式已经存在！");
                    return;
                }
                if (cc.ConnAdd(desc, code))
                {
                    Tips("新增成功！");
                    CloseWindowReferesh();
                }
                else
                {
                    Tips("新增失败！");
                }
            }
            catch (Exception ex)
            {

            }
        }
        private void Tips(string s)
        {
            StringBuilder strScript = new StringBuilder();
            strScript.Append(@"<script language=javascript>
                var divTips=new jSharp.popUpDiv('divMsg');
                document.getElementById('msgContent').innerHTML='" + s + @"';
                divTips.Show();
                var t=setTimeout(function(){
                    divTips.Close();
                    clearTimeout(t);
                },1000);
            </script>");
            this.ClientScript.RegisterStartupScript(this.GetType(), "tips", strScript.ToString());
        }//提示
        private void CloseWindowReferesh()
        {
            StringBuilder strScript = new StringBuilder();
            strScript.Append(@"<script language=javascript>
                if(window.opener)
                {
                    window.opener.location.href=window.opener.location.href;
                    window.close();
                }
            </script>");
            this.ClientScript.RegisterStartupScript(this.GetType(), "Close", strScript.ToString());
        }
    }
}